{! extends "base.html" !}
{! block hscript !}
	<script type="text/javascript" src="{{site.url}}js/jquery.min.js"></script>
{! endblock !}
{! block content !}
   <div class="wrap">

	   <div class="tablenav">
		  <div class="alignleft">&nbsp;</div>
    	  <div class="alignright">
	        {% if pager.prev %}
			<div class="alignleft"><a href="{{site.adminUrl}}comment?page={{ pager.prev}}">&laquo; prev</a></div>
			{% endif %}

			{% if pager.next %}
			<div class="alignright"><a href="{{site.adminUrl}}comment?page={{ pager.next }}">next &raquo;</a></div>
			{% endif %}
            <div class="alignright" style="padding:0px 10px;">Page {{pager.index}}/{{pager.count}} ({{pager.total}})</div>
         </div>

		      <br class="clear"/>
	   </div>
	  <br class="clear"/>

	   <table class="widefat">
		<thead>
			<tr><th></th><th>User</th><th>Post</th><th width="50%">Comment</th><th>Date</th><th width="15%">&nbsp;</th></tr>
			</thead>
			<tbody>
            {%for comment in comments%}
			<tr valign="middle" id="comm-{{comment.id}}">
				<td>{{loop.counter}}</td>
                 <td><strong><a class="row-title" title='mailto "{{comment.email}}"' href="mailto:{{comment.email}}">{{comment.userName}}</a></strong></td>
                 <td><a href="{{site.adminUrl}}post/publish?id={{comment.post.id}}">{{comment.post.title}}</a></td>
                  <td>{{comment.content|escape}}</td>
                  <td>{{comment.date|date:"HH:mm yyyy-MM-dd",site.timezone}}</td>
                  <td>
                  	{%if comment.published|not%}<a href="javascript:approve({{comment.id}})">Approve</a>{%endif%}
                  	&nbsp;<a href="javascript:doDel({{comment.id}})">Delete</a>
                  </td>
        		</tr>
			{%endfor%}
			</tbody>
		</table>

   </div>
{! endblock  !}
{! block bscript !}
<script type="text/javascript"> 
function doDel(id) {
	if (! confirm("delete it?")) {
		return;
	}
 	$.ajax({
 		type: "GET",
 		url: "{{site.adminUrl}}comment/delete?id=" + id,
 		dataType: "json",
 		success: function(data){
 			var hmd = $("#hiddenMessage");
	    	if (data.type == "error") {
	    		hmd.html("<div class='error'>" + data.message + "</div>");
	    	} else {
	    		hmd.html("<div class='info'>" + data.message + "</div>");
	    	}
	    	hmd.show().focus();
	    	$("#comm-" + id).hide();
 		}
 	});
}
function approve(id) {
	$.ajax({
		type: "GET",
		url: "{{site.adminUrl}}comment/approve?id=" + id,
		dataType: "json",
		success: function(data){
			var hmd = $("#hiddenMessage");
    		if (data.type == "error") {
    			hmd.html("<div class='error'>" + data.message + "</div>");
    		} else {
    			hmd.html("<div class='info'>" + data.message + "</div>");
    		}
    		hmd.show().focus();
    		//TODO status change to approved & hidden this click
		}
	});
}
</script>
{! endblock !}